<script setup lang="ts">
import {useStore} from "@/composables/store";
const nav = useStore.useHeaderNav()

const state = reactive({
  navList: [
    {
      title: '产品中心',
      link: '/product',
      value: 'product'
    },
    {
      title: '解决方案',
      link: '/solution',
      value: 'solution'
    },
    {
      title: '合作伙伴',
      link: '/partner',
      value: 'partner'
    },
    {
      title: '客户案例',
      link: '/cases',
      value: 'cases',
    },
    {
      title: '关于华途',
      link: '/about',
      value: 'about'
    },
  ],
});
const currentPath = ref('');
const router = useRouter();
const route = useRoute();
onMounted(() => {
  currentPath.value = location.pathname;
  // const {list} = storeToRefs(nav)
  // console.log(list['footer'])
})

router.afterEach((to: { path: string }) => {
  currentPath.value = to.path;
});
const activeNav = ref()
const setNavActive = (item: { value: any; }) => {
  activeNav.value = item.value
}
const headerMouseLeave = () => {
  activeNav.value = ''
}


</script>

<template>
  <div class="ht-default-header" @mouseleave="headerMouseLeave">
    <div class="ht-default-header-content">
      <div class="ht-default-header-logo">
        <picture>
          <NuxtLink to="/"   target="_blank" >
            <img src="~/assets/logo.png" alt=""/>
          </NuxtLink>
        </picture>
      </div>
      <nav class="ht-default-header-nav">
        <div
            class="ht-default-header-nav-item"
            :class="currentPath.includes(item.link) ? 'active' : ''"
            v-for="(item, index) in state.navList"
            :key="index"
            @mouseover.stop="setNavActive(item)"
        >
          <NuxtLink :to="item.link"  target="_blank">{{ item.title }}</NuxtLink>
        </div>
      </nav>
      <div class="ht-default-header-langs">
        <Lang/>
      </div>
      <div class="ht-default-header-tel">
        <HeadersHeaderTel/>
      </div>
    </div>
    <HeadItem :active-nav="activeNav"/>
    <div class="nav-top-content" :class="activeNav==='product'?activeNav:''">
      <HeadItemProduct/>
    </div>
  </div>
</template>

<style scoped lang="scss">
.ht-default-header {
  width: 100%;
  box-shadow: 0 0.04rem 0.29rem 0.01rem rgba(0, 0, 0, 0.06);
  position: absolute;
  top: 0;
  left: 0;
  z-index: 999;

  .ht-default-header-content {
    display: flex;
    align-items: center;
    width: 100%;
    height: 1.33rem;
    background: #ffffff;

    .ht-default-header-logo {
      margin-left: 0.81rem;

      img {
        width: 2.587rem;
        height: 0.8875rem;
      }
    }

    .ht-default-header-nav {
      display: flex;
      height: 100%;
      margin-left: 4.8rem;

      .ht-default-header-nav-item {
        margin-right: 0.25rem;
        margin-left: 0.4rem;
        position: relative;

        &:first-child {
          margin-left: 0;
        }

        a {
          font-size: 0.25rem;
          height: 100%;
          display: flex;
          align-items: center;
        }

        &:hover {
          a {
            color: #3ab5ec;
          }
        }

        &.active, &:hover {
          a {
            color: #3ab5ec;
          }

          ::after {
            content: '';
            width: 100%;
            height: 3px;
            background: #3ab5ec;
            position: absolute;
            bottom: 0;
            left: 0;
          }
        }
      }
    }

    .ht-default-header-langs {
      margin-left: 3.13rem;
    }

    .ht-default-header-tel {
      margin-left: 0.57rem;
    }
  }
}
.nav-top-content {
  display: none;

  &.product {
    display: block;
  }
}
</style>
